﻿using System;
using Core.Framework.Model.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Core.DataAccess.Model.Project.Wallet
{
    /// <summary>
    /// 钱包模块
    /// </summary>
    public partial class ProjectWalletContext : BaseDbContext<ProjectWalletContext>
    {
        public ProjectWalletContext()
        {
        }

        public ProjectWalletContext(bool isReader) : base(isReader)
        {
        }

        public ProjectWalletContext(DbContextOptions<ProjectWalletContext> options)
            : base(options)
        {
        }

        public virtual DbSet<BillClassify> BillClassify { get; set; }
        public virtual DbSet<BillType> BillType { get; set; }
        public virtual DbSet<PaymentOrder> PaymentOrder { get; set; }
        public virtual DbSet<PaymentType> PaymentType { get; set; }
        public virtual DbSet<WalletBill> WalletBill { get; set; }
        public virtual DbSet<WalletLog> WalletLog { get; set; }
        public virtual DbSet<WalletTransfer> WalletTransfer { get; set; }
        public virtual DbSet<WalletUser> WalletUser { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder
                    // 数据操作日志
                    //.UseLoggerFactory(EFLogger.GetLoggerFactory())
                    .UseSqlServer(CoreStartupHelper.GetConnectionValue("Wallet_SqlServerConnection"));
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<BillClassify>(entity =>
            {
                entity.ToTable("bill_classify");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Title)
                    .HasColumnName("title")
                    .HasMaxLength(20)
                    .IsUnicode(false);

                entity.Property(e => e.Upid)
                    .HasColumnName("upid")
                    .HasDefaultValueSql("((0))");
            });

            modelBuilder.Entity<BillType>(entity =>
            {
                entity.ToTable("bill_type");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Title)
                    .HasColumnName("title")
                    .HasMaxLength(20)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<PaymentOrder>(entity =>
            {
                entity.ToTable("payment_order");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.Pay).HasColumnName("pay");

                entity.Property(e => e.PayType)
                    .HasColumnName("pay_type")
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.Phone)
                    .HasColumnName("phone")
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.Price)
                    .HasColumnName("price")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.ProjectToken)
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.UserKey).HasColumnName("user_key");

                entity.Property(e => e.UserToken)
                    .HasColumnName("user_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<PaymentType>(entity =>
            {
                entity.ToTable("payment_type");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Title)
                    .HasColumnName("title")
                    .HasMaxLength(20)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<WalletBill>(entity =>
            {
                entity.ToTable("wallet_bill");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.BillClassify).HasColumnName("bill_classify");

                entity.Property(e => e.BillType).HasColumnName("bill_type");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.Lable)
                    .HasColumnName("lable")
                    .HasMaxLength(60)
                    .IsUnicode(false);

                entity.Property(e => e.Money)
                    .HasColumnName("money")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.PaymentType).HasColumnName("payment_type");

                entity.Property(e => e.Phone)
                    .HasColumnName("phone")
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.ProjectToken)
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Status).HasColumnName("status");

                entity.Property(e => e.Title)
                    .HasColumnName("title")
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.ToUserKey).HasColumnName("to_user_key");

                entity.Property(e => e.UserKey).HasColumnName("user_key");

                entity.Property(e => e.UserToken)
                    .HasColumnName("user_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<WalletLog>(entity =>
            {
                entity.ToTable("wallet_log");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.BillKey)
                    .HasColumnName("bill_key")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.UserKey).HasColumnName("user_key");

                entity.Property(e => e.UserToken)
                    .HasColumnName("user_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<WalletTransfer>(entity =>
            {
                entity.ToTable("wallet_transfer");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Account)
                    .HasColumnName("account")
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.AccountName)
                    .HasColumnName("account_name")
                    .HasMaxLength(20)
                    .IsUnicode(false);

                entity.Property(e => e.AccountType).HasColumnName("account_type");

                entity.Property(e => e.CompleteTime)
                    .HasColumnName("complete_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.Phone)
                    .HasColumnName("phone")
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.ProjectToken)
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.UserKey).HasColumnName("user_key");

                entity.Property(e => e.UserToken)
                    .HasColumnName("user_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<WalletUser>(entity =>
            {
                entity.ToTable("wallet_user");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Money)
                    .HasColumnName("money")
                    .HasColumnType("decimal(18, 5)");

                entity.Property(e => e.Password)
                    .HasColumnName("password")
                    .HasMaxLength(32)
                    .IsUnicode(false);

                entity.Property(e => e.Phone)
                    .HasColumnName("phone")
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.ProjectToken)
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Token)
                    .HasColumnName("token")
                    .HasMaxLength(21)
                    .IsUnicode(false)
                    .HasDefaultValueSql("(right(newid(),(21)))");

                entity.Property(e => e.UserKey).HasColumnName("user_key");
            });
        }
    }
}
